package code.rocky.chapter10;

public class Suggest133 {

    private static class Apple implements Cloneable {
        public Object clone() {
            try {
                return super.clone();
            }
            catch (CloneNotSupportedException e) {
                throw new Error();
            }
        }
    }

    public static void main(String[] args) {
        final int maxLoops = 10 * 10000;
        int loops = 0;
        long start = System.nanoTime();
        Apple apple = new Apple();
        while (++loops < maxLoops) {
            apple.clone();
        }
        long mid = System.nanoTime();
        System.out.println("clone方法生成对象耗时: " + (mid - start) + " ns");

        while (--loops > 0) {
            new Apple();
        }
        long end = System.nanoTime();
        System.out.println("new 对象耗时: " + (end - mid) + " ns");
    }
}


